<?php

namespace app\common\validate;

use think\Validate;
use app\common\storage\Login as storage;

class Server extends Base
{
	/**
     * 验证规则
     */
    protected $rule = [
        'timestamp'     => 'require',
        'nonce'         => 'require', 
        'token'         => 'require',
        'echostr'       => 'require',
        'signature'     => 'require|vali_signature'
        //'msg_signature' => 'require|'
    ];
    /**
     * 提示消息
     */
    protected $message = [
    	'timestamp.require'                => 'timestamp不能为空',
        'nonce.require'                    => 'nonce不能为空',
        'token.require'                    => 'token不能为空',
        'echostr.require'                  => 'echostr不能为空',
        'signature.require'                => 'signature不能为空',
        'signature.vali_signature'         => 'signature验证失败',
        'msg_signature.require'            => 'msg_signature不能为空',
        'msg_signature.vali_msg_signature' => 'msg_signature验证失败'
    ];
    /**
     * 验证场景
     */
    protected $scene = [

    ];

    protected function vali_signature($value, $rule, $data = []) {
        return $data['signature'] == sha1($data['timestamp'] . $data['nonce'] . $data['token']);
    }

    protected function vali_msg_signature($value, $rule, $data = []) {
        return false;
    }
}
